<template>
	<!-- 兑换记录 邮币首页 -->
	<view class="content">
		<!-- 头部背景 -->
		<view class="head-bg">
			<view class="integral-balance">
				<view class="integral">
					<text>当前邮币</text>
					<text class="number">{{haveCoin}}</text>
				</view>
			</view>
			<view class="bg">
				<image :src="imgUrl+'/static/image/my/integral_bg1.png'" mode=""></image>
			</view>
		</view>
		<!-- <view class="yb_title">
			<view>邮币记录</view>
			<view>
				<text>邮币记录</text>
				<u-icon name="arrow-right" color="#B9BDBC" size="30rpx"></u-icon>
			</view>
		</view> -->
		<u-tabs
			:list="tabsList"
			:activeStyle="{
				color: '#00ABA9',
				fontWeight: 'bold',
				transform: 'scale(1.05)',
			}"
			@click="tabsEvent"
		/>
		<!-- 记录列表 -->
		<view class="record-list">
			<view class="list" v-for="(item,index) in list" :key="index">
				<view class="title-date">
					<view class="title">
						<text>{{item.title}}</text>
					</view>
					<view class="date">
						<text>{{item.createTime.substr(0,16)}}</text>
					</view>
				</view>
				<view class="integral">
					<text>{{item.changeType==0?'+':'-'}}{{item.coinNum}}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	
	import {
		getCoinRecord,
		getDicts
	} from '@/api/home.js'
	export default {
		data() {
			return {
				tabsList: [
					// {
					// 	name: "全部"
					// },
					{
						name: "获取"
					},
					{
						name: "使用"
					}
				],
				list:[],
				queryParams: {
					pageNum: 1,
					pageSize: 10,
					userId: JSON.parse(uni.getStorageSync("userInfo")).userId,
					changeType: 0,
				
				},
				total:0,
				haveCoin:0
			}
		},
		computed:{
			imgUrl(){
				return this.$imgUrl
			}
		},
		onLoad(params){
				this.haveCoin=params.haveCoin
		},
		async created() {
			// activity_use_status0
		
		
			this.list = []
			this.getDic()
			await this.getList()
		},
		onPullDownRefresh() {
			// 下拉刷新时重置数据
			this.queryParams.pageNum = 1;
			this.list = []
			this.getList()
		
		},
		onReachBottom() {
		
			if (this.queryParams.pageNum * this.queryParams.pageSize < this.total) {
				this.queryParams.pageNum++
				this.getList()
			}
		},
		methods: {
			getDic() {
				getDicts('activity_use_status').then(res => {
					console.log(res, '字典');
					let newObj = {
						dictValue: "",
						dictLabel: "全部"
					}
					res.data.unshift(newObj)
					this.typeData = res.data
				})
				// let obj = {
				// 	dictType: 'activity_use_status'
				// }
				// listData(obj).then(res => {
				// 	console.log(res, '字典');
				// })
			},
			// 查询列表
			getList() {
				getCoinRecord(this.queryParams).then(res => {
					console.log(res, '数据');
					res.rows.forEach(item => {
			
						this.list.push(item)
					})
					this.total = res.total
					uni.stopPullDownRefresh(); // 停止下拉刷新动画
				})
			},
			tabsEvent(item) {
				console.log('item', item);
				if(item.name=='获取'){
					this.queryParams.changeType=0
				}else if(item.name=='使用'){
					this.queryParams.changeType=1
				}
				this.list=[]
				this.queryParams.pageNum = 1;
				this.getList()
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		position: absolute;
		left: 0;
		top: 0;
		width: 100%;
		height: 100%;
		background-color: #FFFFFF;
	}
	.head-bg{
		position: relative;
		width: 100%;
		height: 300rpx;
		// background: linear-gradient($base,$change-clor);
		background-color: #28AAA9;
		.integral-balance{
			display: flex;
			align-items: center;
			justify-content: center;
			width: 100%;
			height: 200rpx;
			.integral{
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
				text{
					font-size: 30rpx;
					color: #FFFFFF;
				}
				.number{
					font-size: 60rpx;
					margin-top: 10rpx;
					// font-weight: bold;
				}
			}
		}
		.bg{
			position: absolute;
			left: 0;
			bottom: 0;
			width: 100%;
			height: 40rpx;
			image{
				width: 100%;
				height: 100%;
			}
		}
	}
	
	.yb_title {
		display: flex;
		justify-content: space-between;
		padding: 40rpx 30rpx 20rpx;
		>view:nth-child(1) {
			/* 字体大小 */
			font-size: 30rpx; 
			/* 字体 */
			font-family: "微软雅黑","Microsoft YaHei"; 
			/*  字体粗细：normal 默认 、bold 粗体 、bolder 比粗体更加粗 、lighter 比正常字体细 */
			font-weight: bold; 
		}
		>view:nth-child(2) {
			display: flex;
			/*  字体粗细：normal 默认 、bold 粗体 、bolder 比粗体更加粗 、lighter 比正常字体细 */
			font-weight: lighter; 
		}
	}
	
	::v-deep .u-tabs__wrapper__nav__line {
		background: #28AAA9 !important;
	}
	
	/* 记录列表 */
	.record-list{
		width: 100%;
		background-color: #FFFFFF;
		.list{
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 0 4%;
			height: 140rpx;
			border-bottom: 2rpx solid #f6f6f6;
			.title-date{
				width: 70%;
				height: 100%;
				.title{
					display: flex;
					align-items: center;
					width: 100%;
					height: 60rpx;
					text{
						font-size: 28rpx;
						font-weight: bold;
						color: #222222;
					}
				}
				.date{
					display: flex;
					align-items: center;
					width: 100%;
					height: 60rpx;
					text{
						font-size: 24rpx;
						color: #959595;
					}
				}
			}
			.integral{
				display: flex;
				align-items: center;
				height: 100%;
				text{
					font-size: 28rpx;
					font-weight: bold;
					color: #28AAA9;
				}
			}
		}
	}
</style>